/**
 * 另一棵树的子树
 * @param root
 * @param subRoot
 */
// 判断树是否相等
const isSameTree = (n1: TreeNode | null, n2: TreeNode | null): boolean => {
  if (n1 === null && n2 === null) return true;
  return (
    n1 !== null &&
    n2 !== null &&
    n1.val === n2.val &&
    isSameTree(n1.left, n2.left) &&
    isSameTree(n1.right, n2.right)
  );
};

const isSubtree = (
  root: TreeNode | null,
  subRoot: TreeNode | null
): boolean => {
  if (root === null && subRoot === null) return true;
  if (root === null && subRoot !== null) return false;
  return (
    isSameTree(root, subRoot) ||
    isSubtree(root!.left, subRoot) ||
    isSubtree(root!.right, subRoot)
  );
};

export {};
